﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace WebApplication6
{
    public partial class register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {

                return;
            }
           
            //判断改用户是否已经注册
            string sql = "select count(1) from t_user where role='用户' and username='" + txtusername.Text + "' ";

           int count = Convert.ToInt32(SQLHelper.ExecuteScalar(sql));
            
            if(count>0){
                 
                Response.Write("<script language=javascript>alert('注册失败，该用户名已经存在');window.location.href='register.aspx';</script>");
                return;
            }
            //注册的sql语句
            sql = @"insert into t_user(username,password,truename,address,phone,email,qq,createtime,suo,role) 
            values('" +txtusername.Text+"','"+password.Text+"','"+truename.Text+"','"+address.Text+"','"+phone.Text+"','"
                     +email.Text+"','"+qq.Text+"','"+Convert.ToString(DateTime.Now)+"','"+"正常"+"','"+"用户"+"')" ;

            SQLHelper.ExecuteNonQuery(sql);

            Response.Write("<script language=javascript>alert('注册成功');window.location.href='login.aspx';</script>");
               

           



        }
    }
}
